/*   1:    */ package com.jetbrains.licenseService.util;
/*   2:    */ 
/*   3:    */

import org.jetbrains.annotations.NotNull;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.URL;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */ 
/*  16:    */ public final class ServiceConfig
/*  17:    */ {
/*  18: 28 */   private static final String a = System.getProperty("jb.service.configuration.url", "http://www.jetbrains.com/config/JetBrainsAccount.xml");
/*  19:    */   private static final long b = 120000L;
/*  20:    */   private static volatile String c;
/*  21:    */   private static volatile String d;
/*  22:    */   private static volatile String e;
/*  23:    */   private static volatile String f;
/*  24:    */   private static volatile Boolean g;
/*  25:    */   private static volatile long h;
/*  26:    */   
/*  27:    */   private static void a(String paramString)
/*  28:    */     throws IOException
/*  29:    */   {
/*  30:    */     try
/*  31:    */     {
/*  32: 40 */       Object localObject1 = null;Object localObject2 = null;Object localObject3 = null;Object localObject4 = null;
/*  33: 41 */       Boolean localBoolean = null;
/*  34: 42 */       String str1 = RpcUtil.readFromUrl(new URL(paramString));
/*  35: 43 */       DocumentBuilder localDocumentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
/*  36: 44 */       Document localDocument = localDocumentBuilder.parse(new ByteArrayInputStream(str1.getBytes("UTF-8")));
/*  37: 45 */       NodeList localNodeList1 = localDocument.getElementsByTagName("config");
/*  38: 46 */       if (localNodeList1.getLength() > 0)
/*  39:    */       {
/*  40: 47 */         NodeList localNodeList2 = localNodeList1.item(0).getChildNodes();
/*  41: 48 */         for (int i = 0; i < localNodeList2.getLength(); i++)
/*  42:    */         {
/*  43: 49 */           Node localNode = localNodeList2.item(i);
/*  44: 50 */           if ((localNode instanceof Element))
/*  45:    */           {
/*  46: 51 */             Element localElement = (Element)localNode;
/*  47: 52 */             if ("url".equals(localElement.getTagName()))
/*  48:    */             {
/*  49: 53 */               String str2 = localElement.getAttribute("type");
/*  50: 54 */               String str3 = localElement.getAttribute("value");
/*  51: 55 */               boolean bool = "true".equalsIgnoreCase(localElement.getAttribute("enabled"));
/*  52: 56 */               if ("auth".equalsIgnoreCase(str2))
/*  53:    */               {
/*  54: 57 */                 localObject1 = str3;
/*  55: 58 */                 localBoolean = Boolean.valueOf((localBoolean.booleanValue()) && (bool) ? true : localBoolean == null ? bool : false);
/*  56:    */               }
/*  57: 60 */               else if ("license".equalsIgnoreCase(str2))
/*  58:    */               {
/*  59: 61 */                 localObject2 = str3;
/*  60: 62 */                 localBoolean = Boolean.valueOf((localBoolean.booleanValue()) && (bool) ? true : localBoolean == null ? bool : false);
/*  61:    */               }
/*  62: 64 */               else if ("reset_password".equalsIgnoreCase(str2))
/*  63:    */               {
/*  64: 65 */                 localObject3 = str3;
/*  65:    */               }
/*  66: 67 */               else if ("about".equalsIgnoreCase(str2))
/*  67:    */               {
/*  68: 68 */                 localObject4 = str3;
/*  69:    */               }
/*  70:    */             }
/*  71:    */           }
/*  72:    */         }
/*  73:    */       }
/*  74: 74 */       c = localObject1;
/*  75: 75 */       d = localObject2;
/*  76: 76 */       e = localObject3;
/*  77: 77 */       f = localObject4;
/*  78: 78 */       g = Boolean.valueOf((localBoolean != null) && (localBoolean.booleanValue()));
/*  79: 79 */       h = System.currentTimeMillis();
/*  80:    */     }
/*  81:    */     catch (ParserConfigurationException localParserConfigurationException)
/*  82:    */     {
/*  83: 82 */       throw new IOException(localParserConfigurationException);
/*  84:    */     }
/*  85:    */     catch (SAXException localSAXException)
/*  86:    */     {
/*  87: 85 */       throw new IOException(localSAXException);
/*  88:    */     }
/*  89:    */   }
/*  90:    */   
/*  91:    */   public static boolean isServiceEnabled()
/*  92:    */   {
/*  93:    */     try
/*  94:    */     {
/*  95: 94 */       Boolean localBoolean = g;
/*  96: 95 */       if (localBoolean == null)
/*  97:    */       {
/*  98: 96 */         a(a);
/*  99: 97 */         localBoolean = g;
/* 100:    */       }
/* 101: 99 */       return Boolean.TRUE.equals(localBoolean);
/* 102:    */     }
/* 103:    */     catch (IOException localIOException) {}
/* 104:102 */     return false;
/* 105:    */   }
/* 106:    */   
/* 107:    */   @NotNull
/* 108:    */   public static String getAuthorizationUrl()
/* 109:    */     throws IOException
/* 110:    */   {
/* 111:108 */     a();
/* 112:109 */     String str = c;
/* 113:110 */     if (str == null)
/* 114:    */     {
/* 115:111 */       a(a);
/* 116:112 */       str = c;
/* 117:113 */       if (str == null) {
/* 118:114 */         throw new IOException("Authorization URL not specified");
/* 119:    */       }
/* 120:    */     }
/* 121:117 */     if (str == null) {
/* 122:117 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "com/jetbrains/licenseService/util/ServiceConfig", "getAuthorizationUrl" }));
/* 123:    */     }
/* 124:117 */     return str;
/* 125:    */   }
/* 126:    */   
/* 127:    */   @NotNull
/* 128:    */   public static String getLicenseServiceUrl()
/* 129:    */     throws IOException
/* 130:    */   {
/* 131:122 */     a();
/* 132:123 */     String str = d;
/* 133:124 */     if (str == null)
/* 134:    */     {
/* 135:125 */       a(a);
/* 136:126 */       str = d;
/* 137:127 */       if (str == null) {
/* 138:128 */         throw new IOException("License Service URL not specified");
/* 139:    */       }
/* 140:    */     }
/* 141:131 */     if (str == null) {
/* 142:131 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "com/jetbrains/licenseService/util/ServiceConfig", "getLicenseServiceUrl" }));
/* 143:    */     }
/* 144:131 */     return str;
/* 145:    */   }
/* 146:    */   
/* 147:    */   @NotNull
/* 148:    */   public static String getResetPasswordUrl()
/* 149:    */     throws IOException
/* 150:    */   {
/* 151:136 */     a();
/* 152:137 */     String str = e;
/* 153:138 */     if (str == null)
/* 154:    */     {
/* 155:139 */       a(a);
/* 156:140 */       str = e;
/* 157:141 */       if (str == null) {
/* 158:142 */         throw new IOException("Reset password URL not specified");
/* 159:    */       }
/* 160:    */     }
/* 161:145 */     if (str == null) {
/* 162:145 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "com/jetbrains/licenseService/util/ServiceConfig", "getResetPasswordUrl" }));
/* 163:    */     }
/* 164:145 */     return str;
/* 165:    */   }
/* 166:    */   
/* 167:    */   public static void reset()
/* 168:    */   {
/* 169:149 */     c = null;
/* 170:150 */     d = null;
/* 171:151 */     e = null;
/* 172:    */   }
/* 173:    */   
/* 174:    */   private static void a()
/* 175:    */   {
/* 176:155 */     if (System.currentTimeMillis() - h > 120000L) {
/* 177:156 */       reset();
/* 178:    */     }
/* 179:    */   }
/* 180:    */ }



/* Location:           E:\idea\

 * Qualified Name:     com.jetbrains.licenseService.util.ServiceConfig

 * JD-Core Version:    0.7.0.1

 */